{include file="public/head"}
<script type="text/javascript" src="__STATIC__/lib/UEditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/lib/UEditor/ueditor.all.js"></script>
<style>
    .driver .layui-anim-upbit{z-index: 1000;}
    /*.cityDel{position: absolute;right: -5px;top: -5px;font-size: 5px;color: #0C0C0C;}*/
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>产品名称
                </label>
                <div class="layui-input-inline">
                    <input type="text"  name="title" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>图片
                </label>
                <div class="layui-upload-drag image" id="image" style="width: 168px;">
                    <i class="layui-icon" style="font-size: 40px;">&#xe67c;</i>
                    <p>点击上传</p>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>简介
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="info" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>内容
                </label>
                <div class="layui-input-block">
                    <textarea name="content" id="content"
                              placeholder="请输入内容"
                              style="width: 90%;height: 600px;"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>首页展示
                </label>
                <div class="layui-input-inline">
                    <input type="radio" name="is_home" value="1" title="是">
                    <input type="radio" name="is_home" value="0" title="否" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>排序
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="sort" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="0">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form','layer','upload'],function() {
        $ = layui.jquery;
        let form = layui.form,
            upload = layui.upload,
            layer = layui.layer;
        var ue = UE.getEditor('content');
        ue.addListener("contentChange", function () {
            $("#content").val(ue.getContent());
        });
        //上传
        upload.render({
            elem: '#image'
            ,url: '{:url("Lunbo/LunboImage")}'
            ,done: function(res){
                if (res.code !== 1){
                    layer.msg(res.msg, {icon: 5,time:1000},function () {
                        return false;
                    });
                }
                let dome = '<img src="'+ res.url +'" alt="..." style="width: 168px;height: 75px;">\n' +
                    '<input type="hidden" name="image" value="'+ res.url +'">';
                $('#image').children().remove();
                $('#image').append(dome);
                form.render();
            }
        });
        //监听提交
        form.on('submit(add)',function(data) {
            //发异步，把数据提交给php
            $.post('{:url("add")}', data.field, function (res) {
                if (res.code == 1){
                    layer.msg(res.msg, {icon: 6,time:1000},function () {
                        xadmin.close();
                        xadmin.father_reload();
                    });
                }else {
                    layer.msg(res.msg, {icon: 5,time:1500});
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
